@include('backstage/public/_header')
    <style>
        .add_tab td span #thume {
            line-height: 100px;
            color: #d94040;
            font-size: 14px;
            text-align: center;
        }
    </style>
    <div class="result_wrap">
        <div class="result_title">
            <div class="mark">
                <p>帶<i class="require">*</i>為必填項</p>
            </div>
        </div>
        <form id="form_data">
            {{csrf_field()}}
            <table class="add_tab">
                <tbody>
                    <tr>
                        <th><i class="require">*</i>慘數名稱：</th>
                        <td>
                            <input type="text" class="lg" name="name" id="name">
                            <p>便於自己知道此慘數的作用的名稱</p>
                        </td>
                    </tr>
                    <tr>
                        <th><i class="require">*</i>慘數代碼：</th>
                        <td>
                            <input type="text" onkeyup="value=value.replace(/[^\w{1,}\-\w{1,}|\w{1,}]/g,'')" class="lg" name="code" id="code">
                            <p>在模板中引用的代碼，盡量不要和系統變更重命，可以加前綴，如ttxf_</p>
                        </td>
                    </tr>
                    <tr>
                        <th width="120">慘數類型：</th>
                        <td>
                            <select name="type" id="type">
                                <option value="input">單行文本</option>
                                <option value="textarea">多行文本</option>
                            </select>
                            <span><i class="fa fa-exclamation-circle yellow"></i>慘數的類型：單行文本所保存內容較小，多行文本可保存較多內容</span>
                        </td>
                    </tr>
                    <tr>
                        <th width="120">慘數分類：</th>
                        <td>
                            <select name="prmtype" id="prmtype">
                            @foreach($setting_type as $k=>$v)
                                <option value="{{$k}}">{{$v}}</option>
                            @endforeach
                            </select>
                            <span><i class="fa fa-exclamation-circle yellow"></i>慘數的分類：默認網站設置</span>
                        </td>
                    </tr>
                    <tr>
                        <th>慘數說明：</th>
                        <td>
                            <input type="text" class="lg" name="tip" id="tip">
                            <p>用來更詳細的說明此慘數的作用</p>
                        </td>
                    </tr>
                    <tr>
                        <th>排序：</th>
                        <td>
                            <input type="text" onkeyup="value=value.replace(/[^\d{1,}\-\d{1,}|\d{1,}]/g,'')" name="order_sn" placeholder="0" maxlength="3" id="order_sn" >
                            <span><i class="fa fa-exclamation-circle yellow"></i>只能是數字,該慘數在管理列表中的排序，越大越靠前</span>
                        </td>
                    </tr>
                </tbody>
            </table>
            <div class="btn_group">
                <input type="button" value="提交" id="btnSub" onclick="onSubmit();">
                <input type="button" class="back" onclick="history.go(-1)" value="返回">
            </div>
        </form>
        <div class="tips">
            <h3>添加新慘數說明</h3>
            <p>1、帶<i class="require">*</i>為必填項，不允許為空</p>
            <p>2、頂級分類無父分類</p>
            <p>3、分類唯壹標誌為分類鏈接的網址標識，排序：數字越大越靠前</p>
            <p>4、點擊提交 -&gt; 新增慘數，返回-&gt; 回到基本設置頁面</p>
        </div>
    </div>
    <script type="text/javascript">
       
        var vfTime = 2;
        var timer=null;
        function setTime(){
            vfTime --;
            if(vfTime<=0){
                vfTime = 0;
                clearInterval(timer);
            }
        }

        function onSubmit(){
            var name = $("#name").val();
            var code = $("#code").val();
            if (vfTime!=0 && timer!=null){
                layer.msg('操作過於頻繁', {icon: 7,anim: 6});
                // setTimeout(function(){$("#chiContent").focus();}, 1500);
                return false;
            }
            if (name==''){
                layer.msg('慘數名稱不能為空', {icon: 5,anim: 6});
                // setTimeout(function(){$("#chiContent").focus();}, 1500);
                return false;
            }
            if (code=='') {
                layer.msg('慘數代碼不能為空', {icon: 5,anim: 6});
                setTimeout(function(){$("#type_name").focus();},0);
                return false;
            }
            
            var form = new FormData(document.getElementById("form_data"));
//             var req = new XMLHttpRequest();
//             req.open("post", "${pageContext.request.contextPath}/public/testupload", false);
//             req.send(form);
            $.ajax({
                url:"{{$doadd}}",
                type:"post",
                data:form,
                processData:false,
                contentType:false,
                dataType : "json",
                success:function(data){
                    if(data.status==1){
                        layer.msg(data.message, {icon: 6});
                        setTimeout(function(){
                            window.location.href=data.jumpUrl;
                        },2000);
                    }else if(data.status==-1){
                        layer.alert(data.message, {icon: 2,anim:6});
                    }else{
                        layer.msg(data.message, {icon: 5});
                    }
                    clearInterval(timer);
                    timer = setInterval(setTime, 1000, "1");
                    
                },
                error:function(e){
                    layer.msg(e, {icon: 5,anim: 6});
                    clearInterval(timer);
                    timer = setInterval(setTime, 1000, "1");
                }
            });
        }
    </script>
@include('backstage/public/_footer')